#include "status.h"

void getFiles(string directoryPath, vector<string> &files)
{
    QString path = string2QString(directoryPath);
//    QString path = QString::fromStdString(directoryPath);
    QStringList filters;
    filters << "*.jpg" << "*.png";
    QDir dir(path);
    if(!dir.exists())
    {
        return;
    }
    dir.setNameFilters(filters);
    QFileInfoList list = dir.entryInfoList();

    int file_count = list.count();
    for(int i = 0; i < file_count; ++i)
        files.push_back(QString2string(list.at(i).filePath()));
}

void Status::updateStatus()
{
//    hasSvaedNowEntry =false;
    nowSelection = Empty_Type;
    AnnotationImage annImg(imageFiles[nowImageIndex]);
    nowAnnImage = annImg;
    ImageAnnotation imgAnn(imageFiles[nowImageIndex], getAnnNameByImageName(imageFiles[nowImageIndex]), &nowAnnImage);
    nowImageAnn = imgAnn;
    nowAnnImage.setPImageAnn(&nowImageAnn);
    nowImageAnn.setPAnnImage(&nowAnnImage);
}

void Status::createStatus(const string &directory)
{
    imageDir = directory;
    getFiles(directory, imageFiles);
    imageCounts = imageFiles.size();
    updateStatus();
}
